function circular(id, data, title) {
    document.getElementById(id).innerHTML = "";
    document.getElementById(id).removeAttribute("_echarts_instance_");
    var myChart = echarts.init(document.getElementById(id));
    myChart.setOption({
        title: {
            text: title,
            left: 'center'
        },
        tooltip: {
            trigger: 'item',
            formatter: "{a} <br/>{b} : {c} ({d}%)"
        },
        legend: {
            orient: 'vertical',
            left: 'left',
        },
        series: [
            {
                name: '提案',
                type: 'pie',
                radius: '50%',
                center: ['50%', '60%'],
                data: data,
                label: {
                    normal: {
                        formatter: '{b}:{c}: ({d}%)',
                        textStyle: {
                            fontWeight: 'normal',
                            fontSize: 15
                        }
                    }
                },
                emphasis: {
                    itemStyle: {
                        shadowBlur: 10,
                        shadowOffsetX: 0,
                        shadowColor: 'rgba(0, 0, 0, 0.5)'
                    }
                },
                normal: {
                    label: {
                        show: true,
                        formatter: '{b} : {c} ({d}%)'
                    },
                    labelLine: {show: true}
                }
            }
        ]
    })
}


function zhuheng(id, data, title) {
    document.getElementById(id).innerHTML = "";
    document.getElementById(id).removeAttribute("_echarts_instance_");
    var dataname = [], datavalue = [];

    for (var i = 0; i < data.length; i++) {
        datavalue.push(data[i].value);
        dataname.push(data[i].name)
    }
    var myChart = echarts.init(document.getElementById(id));
    myChart.setOption({
        title: {
            text: title,
        },

        xAxis: {
            type: 'category',
            data: dataname,
            axisLabel: {
                interval: 0,
                rotate: 30,//倾斜度 -90 至 90 默认为0
                margin: 2,
                textStyle: {
                    fontWeight: "bolder",
                    color: "#000000"
                }
            }
        },
        yAxis: {
            type: 'value'
        },

        series: [{
            data: datavalue,
            type: 'bar',
            showBackground: true,
            backgroundStyle: {
                color: 'rgba(180, 180, 180, 0.2)'
            }, itemStyle: {
                normal: {
                    label: {
                        show: true, //开启显示
                        position: 'top', //在上方显示
                        textStyle: { //数值样式
                            color: 'black',
                            fontSize: 16
                        }
                    }
                }
            },
        }]

    })
}

function zhushu(id, data, title) {
    document.getElementById(id).innerHTML = "";
    document.getElementById(id).removeAttribute("_echarts_instance_");
    var myChart = echarts.init(document.getElementById(id));
    var dataname = [], datavalue = [];

    for (var i = 0; i < data.length; i++) {
        datavalue.push(data[i].value);
        dataname.push(data[i].name)
    }
    myChart.setOption({
        title: {
            text: title,
        },
        tooltip: {
            trigger: 'axis',
            axisPointer: {
                type: 'shadow'
            }
        },

        grid: {
            left: '3%',
            right: '4%',
            bottom: '3%',
            containLabel: true
        },
        xAxis: {
            type: 'value',
            boundaryGap: [0, 0.01]
        },
        yAxis: {
            type: 'category',
            data: dataname
        },
        series: [
            {
                name: '提案数',
                type: 'bar',
                data: datavalue,
                itemStyle: {
                    normal: {
                        label: {
                            show: true, //开启显示
                            position: 'top', //在上方显示
                            textStyle: { //数值样式
                                color: 'black',
                                fontSize: 16
                            }
                        }
                    }
                },
            }]
    })
}

function yibiaopan(id, data, title) {
    document.getElementById(id).innerHTML = "";
    document.getElementById(id).removeAttribute("_echarts_instance_");
    var myChart = echarts.init(document.getElementById(id))
    var option = {
        tooltip: {
            formatter: "{a} <br/>{b} : {c}%"
        },
        toolbox: {
            feature: {
                restore: {},
                saveAsImage: {}
            }
        },

        series: [
            {
                name: title,
                type: 'gauge',
                detail: {formatter: '{value}%'},
                axisLine: {            // 坐标轴线
                    lineStyle: {       // 属性lineStyle控制线条样式
                        color: [[0.2, '#c23531'], [0.8, '#63869e'], [1, '#91c7ae']]
                    }
                },
                data: [{value: data, name: title}]
            }
        ]
    };

    myChart.setOption(option)
}

function fenxiover(year) {

    $.ajax({
        type: "GET",
        url: baseURL + "/sys/tianan/fenxiover/" +year,
        success: function (r) {
            yibiaopan("over", (r.data * 100).toFixed(2), "提案完结率")
        }
    })
}

function fenxiovertime(year) {
    $.ajax({
        type: "GET",
        url: baseURL + "/sys/tianan/fenxiovertime/" + year,
        success: function (r) {
            yibiaopan("overtime", (r.data * 100).toFixed(2), "提案超时率")
        }
    })
}

function fenximanyi(year) {
    $.ajax({
        type: "GET",
        url: baseURL + "/sys/tianan/fenximanyi/" +year,
        success: function (r) {
            circular('manyi', r.data, "满意度分析")
        }
    })
}

function fenxitype(year) {
    $.ajax({
        type: "GET",
        url: baseURL + "/sys/tianan/fenxitype/" + year,
        success: function (r) {
            var sum = 0;
            var value = "";
            for (var i = 0; i < r.data.length; i++) {
                sum = Number(sum) + Number(r.data[i].value);
                value = value + "" + r.data[i].name + "：<span style='color: red;'>" + r.data[i].value + "件</span>"
            }
            $(".total").html("一、总件数：<span style='color: red;'>" + sum + "</span>件。");
            $(".totalqizhong").html("其中：" + value + "。");
            circular('type', r.data, "提案类别分析")
        }
    })
}

function fenxitypes(year) {
    $.ajax({
        type: "GET",
        url: baseURL + "/sys/tianan/fenxitypes/" +year,
        success: function (r) {
            var value = "";
            for (var i = 0; i < r.data.length; i++) {
                value = value + "" + r.data[i].name + "：<span style='color: red;'>" + r.data[i].value + "件、</span>"
            }
            var lastIndex = value.lastIndexOf('、');
            if (lastIndex > -1) {
                value = value.substring(0, lastIndex) + value.substring(lastIndex + 1, value.length);
            }
            if (value != "") {

                $(".twoqizhong").html("" + value + "。");

            }

            circular('types', r.data, "提案类型分析")
        }
    })
}

function fenxiliantype(year) {
    $.ajax({
        type: "GET",
        url: baseURL + "/sys/tianan/fenxiliantype/" + year,
        success: function (r) {
            var value = "";
            for (var i = 0; i < r.data.length; i++) {
                value = value + "" + r.data[i].name + "：<span style='color: red;'>" + r.data[i].value + "件、</span>"
            }
            var lastIndex = value.lastIndexOf('、');
            if (lastIndex > -1) {
                value = value.substring(0, lastIndex) + value.substring(lastIndex + 1, value.length);
            }
            if (value != "") {

                $(".threeqizhong").html("" + value + "。");
            }
            circular('liantype', r.data, "立案类型分析")
        }
    })
}

function fenxiliandept(year) {
    $.ajax({
        type: "GET",
        url: baseURL + "/sys/tianan/fenxiliandept/" + year,
        success: function (r) {
            var value = "部门承接情况：";
            for (var i = 0; i < r.data.length; i++) {
                value = value + "" + r.data[i].name + "：<span style='color: red;'>" + r.data[i].value + "件、</span>"
            }
            var lastIndex = value.lastIndexOf('、');
            if (lastIndex > -1) {
                value = value.substring(0, lastIndex) + value.substring(lastIndex + 1, value.length);
            }
            if (value != "") {

                $(".fourqizhong").html("" + value + "。");
            }
            zhuheng('liandept', r.data, "部门处理数量分析")
        }
    })
}

function fenxilianren(year) {
    $.ajax({
        type: "GET",
        url: baseURL + "/sys/tianan/fenxilianren/" + year,
        success: function (r) {
            zhushu('lianren', r.data, "提案人汇总")
        }
    })
}

$(function () {
    function inityear() {
        $.get(baseURL + "sys/tianan/listyear", function (r) {
            $("#listyear").html("");
            for (var i = 0; i < r.year.length; i++) {
                $("#listyear").append("<option value='" + r.year[i] + "' >" + r.year[i] + "</option>");

            }
            $('#listyear').selectpicker({
                width: '160px'
            });
            var year=$('#listyear').val();
            fenxiover(year);
            fenxiovertime(year);
            fenximanyi(year);
            fenxitype(year);
            fenxitypes(year);
            fenxiliantype(year);
            fenxiliandept(year);
            fenxilianren(year);

        });

    }
    inityear();
    $("#listyear").change(function () {
        var year=$('#listyear').val();

        fenxiover(year);
        fenxiovertime(year);
        fenximanyi(year);
        fenxitype(year);
        fenxitypes(year);
        fenxiliantype(year);
        fenxiliandept(year);
        fenxilianren(year);
    });




});
